/*
 *
 * Copyright (C) 2014 Rigaku Americas Corporation
 *                    9009 New Trails Drive
 *                    The Woodlands, TX, USA  77381
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *    * Redistributions of source code must retain the above copyright
 *      notice(s), this list of conditions and the following disclaimer.
 *    * Redistributions in binary form must reproduce the above copyright
 *      notice(s), this list of conditions and the following disclaimer in the
 *      documentation and/or other materials provided with the distribution.
 *    * Neither the name of the Rigaku Americas Corporation nor the
 *      names of its contributors may be used to endorse or promote products
 *      derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL RIGAKU AMERICAS CORPORATION BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA OR PROFITS; OR BUSINESS INTERUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 *
 */
///////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//         This example code is from the book:
//
//           Object-Oriented Programming with C++ and OSF/Motif
//         by
//           Douglas Young
//           Prentice Hall, 1992
//           ISBN 0-13-630252-1	
//
//         Copyright 1991 by Prentice Hall
//         All Rights Reserved
//
//  Permission to use, copy, modify, and distribute this software for 
//  any purpose except publication and without fee is hereby granted, provided 
//  that the above copyright notice appear in all copies of the software.
///////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////////////////////////////
// UIComponent.h: Base class for all C++/Motif UI components
///////////////////////////////////////////////////////////////
#ifndef UIComponent_H
#define UIComponent_H
#define UICOMPONENT_H
#include <Xm/Xm.h>

//
// If this is not set, bx and cgx assume an old base class. App generation
// 	may not work at runtime.
//
#define cxx_bx_compat

// This structure is for capturing app-defaults values for a Class

typedef struct _UIAppDefault
{
    const char*		wName;		// Widget name
    const char*		cInstName;	// Name of class instance (nested class)
    const char*		wRsc;		// Widget resource
    char*		value;		// value read from app-defaults
} UIAppDefault;

// UIComponent Class
class UIComponent {
    
  private:
    
    // Interface between XmNdestroyCallback and this class
    
    static void widgetDestroyedCallback ( Widget, 
					  XtPointer, 
					  XtPointer );
    
  protected:

    char    *_name;
    Widget   _w;    
    
    // Protect constructor to prevent direct instantiation
    
    UIComponent ( const char * );
    
    void installDestroyHandler(); // Easy hook for derived classes
    
    // Called by widgetDestroyedCallback() if base widget is destroyed
    
    virtual void widgetDestroyed(); 
    
    // Loads component's default resources into database
    
    void setDefaultResources ( const Widget , const String *);
    
    // Retrieve resources for this clsss from the resource manager
    
    void getResources ( const XtResourceList, const int );

    // Initialize the app defaults structure for a class

    void initAppDefaults ( const Widget, const char *, UIAppDefault * );

    // Set the app defaults for an instance of a class

    void setAppDefaults ( const Widget, UIAppDefault *, const char* inst_name = NULL, Boolean override_inst = False);
   
  public:
    
    virtual ~UIComponent();  // Destructor
    
    // Manage the entire widget subtree represented
    // by this component. Overrides BasicComponent method
    
    virtual void manage();   // Manage and unmanage widget tree
    virtual void unmanage();

    const Widget baseWidget() { return _w; }
    
    // Public access functions
    
    virtual const char *const className();
};

typedef struct _UICbStruct
{
    UIComponent *object;             // this pointer
    XtPointer       client_data;         // client data 
} UICallbackStruct;

#endif
